//
//  UIBarButtonItem+Category.swift
//  SwiftProject
//
//  Created by 杨晓生 on 16/8/4.
//  Copyright © 2016年 XS. All rights reserved.
//

import UIKit
//extension 要导入UIKit ，swift的extension类似于OC的category
extension UIBarButtonItem{
    
    //这里的class相当于OC的 +
    class func creatBarButtonItem(imageName:String,target: AnyObject?,action:Selector) -> UIBarButtonItem {
        let button = UIButton()
        button.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        return UIBarButtonItem(customView: button)

    }
}
